package 剑指专题.队列栈;


/*
 * Author：江松
 * Date：2023/3/27 10:16
 *
 包含min函数的栈：
 用1个栈存储元素，用1个栈存储当前最小值
 */

import java.util.Stack;

public class Main2 {
    Stack<Integer>stack=new Stack<>();
    Stack<Integer>minStack=new Stack<>();
    public void push(int node) {
        stack.push(node);
        if(minStack.isEmpty()||node<minStack.peek()){
            minStack.push(node);
        }else{
            minStack.push(minStack.peek());
        }
    }

    public void pop() {
        stack.pop();
        minStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}
